<?php
class news
{	var $row;
	var $obj;
	var $city;
	var $db;
	var $objId;
	var $id;
	function __construct($obj, $city, $objId, $edit=false)
	{		$this->edit=$edit;		$this->db=substr($obj, 0, 1).'n';
		if($obj=='nets')
		{			$this->db='main';
			//$this->city='nets_news';
		}
		$this->city=$city;
		$this->objId=$objId;
		$this->obj=$obj;		echo ('
		<link rel="stylesheet" type="text/css" href="style/newsStyle.css" />
		');	}
	function showANews($id, $name, $text, $date, $link, $textSubstr="")
	{		if($textSubstr)
		{			if(strlen($text)>$textSubstr)
			{				$text=mb_substr($text, 0, $textSubstr, 'utf-8').'...<a href="fullnews.php?id='.$this->objId.'&news_id='.$id.'&obj='.$this->obj.'&city='.$this->city.'">Полностью</a>';
				if($this->edit)
					$text=mb_substr($text, 0, $textSubstr, 'utf-8').'...<a href="fullnewscab.php?id='.$this->objId.'&news_id='.$id.'&obj='.$this->obj.'&city='.$this->city.'">Полностью</a>';			}
		}
		$text=nl2br($text);
		$date=date_create($date);
		$date=date_format($date, 'd-m-Y');
		$imgSrc='pictures/'.$this->obj.'newspics/'.$this->city.'/'.$id.'.jpg';
		if($this->obj=='nets')$imgSrc='pictures/'.$this->obj.'newspics/'.$id.'.jpg';
		if(file_exists($imgSrc))$foto='<img class="newsPic" src="'.$imgSrc.'" />';		echo ('
		<div class="new">
			<table border="0" cellspacing="0" cellpadding="0">
				<tr height="20">
					<td>
						<div class="newsdate" align="center">
							'.$date.'
						</div>
					</td>
					<td>
						<div class="newsName">
							<a href="'.$link.$id.'">'.$name.'</a>
						</div>
					</td>
				</tr>
				<tr height="40">
					<td class="newsinfo" valign="top">
						<div class="newsfoto">
                        	'.$foto.'
						</div>
					</td>
					<td class="newsbody">
						<div class="newstext">
							'.$text.'
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center" class="newspers">
					');
                    	if($this->edit)
						{
							echo ('
							<center>
								<a class="belink_grey" href="edit'.$this->obj.'news.php?city='.$_GET['city'].'&id='.$id.'">Редактировать</a>
							</center>
							');
						}
					echo ('
					</td>
				</tr>
			</table>
		</div>
		');	}
	function showNews($link, $limit="", $textSubstr="", $maxheight="")
	{		if($limit)$LIMIT="LIMIT ".$limit;		$aConnect=new connect($this->db);
		$newsNum=mysql_num_rows($aConnect->select_all($this->city, "WHERE ".$this->obj."_id='".$this->objId."'"));
		$res=$aConnect->select_all($this->city, "WHERE ".$this->obj."_id='".$this->objId."' ORDER BY data DESC $LIMIT");
		if($limit && $newsNum>$limit)
		{
			$showAllLink='
			<div align="center">
				<a href="news.php?city='.$this->city.'&obj='.$this->obj.'&id='.$this->objId.'" class="belink">Все новости ('.$newsNum.')
				</a>
			</div>
	      	';
	      	if($this->edit)
	    	$showAllLink='
			<div align="center">
				<a href="newscab.php?city='.$this->city.'&obj='.$this->obj.'&id='.$this->objId.'" class="belink">Все новости ('.$newsNum.')
				</a>
			</div>
	      	';
		}
		echo ('
		<div class="news" style="overflow: hidden; max-height: '.$maxheight.';">
			');
		while($row=mysql_fetch_array($res))
		{
			$this->showANews($row['id'], $row['name'], $row['stext'], $row['data'], $link, $textSubstr);
		}
		echo ('
		</div>
		'.$showAllLink.'
		');	}
}
?>